package com.jg.service.impl;

import com.jg.entity.EmployeeInsurance;
import com.jg.entity.Employees;
import com.jg.mapper.EmployeeInsuranceMapper;
import com.jg.mapper.EmployeesMapper;
import com.jg.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 86130
 * @version 1.0
 * @description: TODO
 * @date 2025/6/6 上午9:06
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeesMapper employeeMapper;

    @Autowired
    private EmployeeInsuranceMapper employeeInsuranceMapper;

    @Transactional  //  开启事务
    @Override
    public int insert(Employees employee, EmployeeInsurance employeeInsurance) {
        //新增员工
        employeeMapper.insert(employee);
        //获取员工的id
        Integer employeeId = employee.getEmployeeId();
        System.out.println("员工id："+employeeId);

        //新增员工保险
        employeeInsurance.setEmployeeId(employeeId);
        return employeeInsuranceMapper.insert(employeeInsurance);
    }
}
